<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将数组中的所有键名修改为全大写或小写</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.array.html">« 数组 函数</a></li>
      <li style="float: right;"><a href="function.array-chunk.html">array_chunk »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.array.html">数组 函数</a></li>
    <li>将数组中的所有键名修改为全大写或小写</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.array-change-key-case" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_change_key_case</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_change_key_case</span> &mdash; <span class="dc-title">将数组中的所有键名修改为全大写或小写</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.array-change-key-case-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_change_key_case</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$case</code><span class="initializer"> = <strong><code>CASE_LOWER</code></strong></span></span>): <span class="type">array</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_change_key_case()</strong></span> 将 <code class="parameter">array</code>
     数组中的所有键名改为全小写或大写。本函数不改变数字索引。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.array-change-key-case-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       需要操作的数组。
      </p>
     </dd>

    

    
     <dt>
<code class="parameter">case</code></dt>

     <dd>

      <p class="para">
       可以在这里用两个常量，<strong><code>CASE_UPPER</code></strong> 或
     <strong><code>CASE_LOWER</code></strong>（默认值）。
      </p>
     </dd>

    

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-change-key-case-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    返回一个键全是小写或者全是大写的数组；如果输入值（<code class="parameter">array</code>）不是一个数组，则返回 <strong><code>null</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-change-key-case-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="function.array-change-key-case.example-1">
    <p><strong>示例 #1 <span class="function"><strong>array_change_key_case()</strong></span>例一</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$input_array&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"FirSt"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SecOnd"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">array_change_key_case</span><span style="color: #007700">(</span><span style="color: #0000BB">$input_array</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CASE_UPPER</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [FIRST] =&gt; 1
    [SECOND] =&gt; 4
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.array-change-key-case-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    如果一个数组中的多个键名经过本函数后变成一样的话（例如
     &quot;<code class="literal">keY</code>&quot; 和 &quot;<code class="literal">kEY</code>&quot;），最后一个值将覆盖其它的值。
   </p>
  </p></blockquote>
 </div>

  </div></div></div></body></html>